roundedbox: Fix border radius grow algorithm
authorBenjamin Otte <otte@redhat.com>
Mon, 13 Jun 2011 03:49:12 +0000 (05:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 13 Jun 2011 13:01:52 +0000 (15:01 +0200)
When one radius gets to 0, the other should be set to 0, too. Otherwise
the paths constructed from it will not be correct.

gtk/gtkroundedbox.c

index 843328257edace87192d6b05f465535a37c639bb..3414e484f35d80e3def48ae2b9034ecbf8379a87 100644 (file)
@@ -81,6 +81,20 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox    *box,
   g_free (bottom_left_radius);
 }
 
+static void
+gtk_css_border_radius_grow (GtkCssBorderCornerRadius *corner,
+                            double                    horizontal,
+                            double                    vertical)
+{
+  corner->horizontal += horizontal;
+  corner->vertical += vertical;
+
+  if (corner->horizontal <= 0 || corner->vertical <= 0)
+    {
+      corner->horizontal = 0;
+      corner->vertical = 0;
+    }
+}
 void
 _gtk_rounded_box_grow (GtkRoundedBox *box,
                        double         top,
@@ -110,22 +124,10 @@ _gtk_rounded_box_grow (GtkRoundedBox *box,
       box->box.height += top + bottom;
     }
 
-  if (box->border_radius.top_left.horizontal)
-    box->border_radius.top_left.horizontal = MAX (0, box->border_radius.top_left.horizontal + left);
-  if (box->border_radius.top_left.vertical)
-    box->border_radius.top_left.vertical = MAX (0, box->border_radius.top_left.vertical + top);
-  if (box->border_radius.top_right.horizontal)
-    box->border_radius.top_right.horizontal = MAX (0, box->border_radius.top_right.horizontal + right);
-  if (box->border_radius.top_right.vertical)
-    box->border_radius.top_right.vertical = MAX (0, box->border_radius.top_right.vertical + top);
-  if (box->border_radius.bottom_right.horizontal)
-    box->border_radius.bottom_right.horizontal = MAX (0, box->border_radius.bottom_right.horizontal + right);
-  if (box->border_radius.bottom_right.vertical)
-    box->border_radius.bottom_right.vertical = MAX (0, box->border_radius.bottom_right.vertical + bottom);
-  if (box->border_radius.bottom_left.horizontal)
-    box->border_radius.bottom_left.horizontal = MAX (0, box->border_radius.bottom_left.horizontal + left);
-  if (box->border_radius.bottom_left.vertical)
-    box->border_radius.bottom_left.vertical = MAX (0, box->border_radius.bottom_left.vertical + bottom);
+  gtk_css_border_radius_grow (&box->border_radius.top_left, left, top);
+  gtk_css_border_radius_grow (&box->border_radius.top_right, right, bottom);
+  gtk_css_border_radius_grow (&box->border_radius.bottom_right, right, top);
+  gtk_css_border_radius_grow (&box->border_radius.bottom_left, left, bottom);
 }
 
 void